const service = require('../../../utils/utilService.js')

Page({
  data: {
    currentLevel: 0,
    levels: ["0", "v1", "v2", "v3", "v4", "v5"],
    level_texts: [],
    richText: ''
  },
  onLoad: function (options) {
    wx.showLoading({
      title: '加载中',
    });
    this.requestHeaderContent()
    this.requestBottomContent()
    this.setData({ currentLevel: options.currentLevel })
  },

  requestHeaderContent: function () {
    var that = this
    service.getSetting(8,
      function (data) {
        wx.hideLoading() 
        that.setData({ level_texts: that.splitStr(data.value)})
      },
      function (error) {
        wx.hideLoading()  
        wx.showToast({
          title: error.data.message,
          icon: 'none',
          duration: 2000,
        })
      })
  },
  requestBottomContent: function () {
    var that = this
    service.getSetting(15,
      function (data) {
        wx.hideLoading()  
        that.setData({ richText: data.value })
      },
      function (error) {
        wx.hideLoading()  
        wx.showToast({
          title: error.data.message,
          icon: 'none',
          duration: 2000,
        })
      })
  },
  splitStr: function(value) {
    var subStr = new RegExp('<[^>]*>')
    var str = value.split(subStr).join("-")
    str = str.split(' ').join("")
    var array = str.split('-')
    var newArray = []
    for (var index in array) {
      if (array[index].length > 0) {
        newArray.push(array[index])
      }
    }
    return newArray
  }
});